//
//  CCSDGoodAssessTypeCell.m
//  Ccsd_user
//
//  Created by 张露杰 on 17/9/11.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "CommentCell.h"

@implementation CommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(void)loadCellWithData:(NSDictionary *)data
{
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    //头像
    UIImageView *imageView = [UIImageView new];
    [self.contentView addSubview:imageView];
    [imageView.layer setCornerRadius:18*screenW_6];
    imageView.layer.masksToBounds = YES;
    imageView.clipsToBounds = YES;
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(17*screenW_6));
        make.height.equalTo(@(36*screenW_6));
        make.width.equalTo(@(36*screenW_6));
        make.top.equalTo(self.contentView).offset(18*screenW_6);
    }];
    
    
    //姓名
    UILabel *nameLabel = [UILabel new];
    [self.contentView addSubview:nameLabel];
    nameLabel.textColor = TextBlackGray;
    nameLabel.font = [UIFont systemFontOfSize:14*screenW_6];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(15*screenW_6);
        make.top.equalTo(self.contentView).offset(18*screenW_6);
        make.height.equalTo(@(18*screenW_6));
        make.width.equalTo(self.contentView).offset(-15*screenW_6);
    }];
    
    //时间
    UILabel *timeLabel = [UILabel new];
    timeLabel.textColor = TextGray;
    timeLabel.font = [UIFont systemFontOfSize:12*screenW_6];
    [self.contentView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(15*screenW_6);
        make.top.equalTo(nameLabel.mas_bottom).offset(0);
        make.height.equalTo(@(18*screenW_6));
        make.width.equalTo(@(SCREENW-80*screenW_6));
    }];
    
    //内容
    UILabel *contentLabel = [UILabel new];
    [self.contentView addSubview:contentLabel];
    contentLabel.textColor = TextBlack;
    contentLabel.font = [UIFont systemFontOfSize:15*screenW_6];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(15*screenW_6);
        make.top.equalTo(timeLabel.mas_bottom).offset(5*screenW_6);
        make.width.equalTo(@(SCREENW-80*screenW_6));
    }];
    
    //线条
    UIView *lineView = [UIView new];
    lineView.backgroundColor = LineColor;
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15*screenW_6);
        make.top.equalTo(contentLabel.mas_bottom).offset(20*screenW_6);
        make.width.equalTo(@(SCREENW-30*screenW_6));
        make.height.equalTo(@(1*screenW_6));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
    }];
    
    //数据加载
//    [imageView sd_setImageWithURL:[NSURL URLWithString:data[@"user"]?data[@"user"][@"photo"]:@""] placeholderImage:[UIImage imageNamed:@"backImage"]];
    [imageView sd_setImageWithURL:[NSURL URLWithString:data[@"headPortrait"]] placeholderImage:[UIImage imageNamed:@"forumHeader"]];
    nameLabel.text = data[@"nickName"];
    timeLabel.text = data[@"createDate"];
    contentLabel.text = data[@"content"];
    [contentLabel sizeToFit];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
         make.height.equalTo(@(contentLabel.frame.size.height));
    }];
    
}

@end
